from typing import Optional

import torch
from torch.utils.data import Dataset, DataLoader

class DataGenerator:
    def __init__(self,data: Optional[list] =None):
        #需要装成tensor
        self.data=[ [torch.LongTensor(t[0]),torch.LongTensor(t[1])]   for  t in data]

    def __len__(self):
        return len(self.data)

    def __getitem__(self, index):
        return self.data[index]

    def build_data_loader(self,batch_size,shuffle=True):
        return DataLoader(self.data,batch_size,shuffle)
